<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<input type="hidden" id="eid">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 组织机构
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="管理部门"><i
                        class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i
                        class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input type="hidden" id="ComPidorDepTid" name="ComPidorDepTid">
                    <input type="hidden" id = "compID" name="compID">
                    <input type="hidden" id = "depID" name="depID">
                    <div class="select-list">
                        <ul>
                            <li>
                                员工编号：<input type="text" name="Badge"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="Name"/>
                            </li>
                            <li>
                                公司名称：<input type="text" name="compname"/>
                            </li>
                            <li>
                                岗位级别：<select name="jobGradename" th:with="type=${@dict.getType('oCD_jobgrade')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
                   shiro:hasPermission="jinpeng:emp:detail">
                    <i class="fa fa-edit"></i> 查看
                </a>

                <button type="button" id="modal" class="btn btn-primary" data-toggle="modal"
                        data-target="#myModal6">小模态窗口
                </button>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="emp-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js"/>

<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('jinpeng:edit')}]];
    var removeFlag = [[${@permission.hasPermi('jinpeng:remove')}]];
    var prefix = ctx + "jinpeng";

    $(function () {
        $("#modal").hide();
        var panehHidden = false;

        if ($(this).width() < 800) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});
        queryUserList();
        queryDeptTree();
        $("#effectdate").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    });

    function queryUserList() {
        var options = {
            id: "emp-table",
            code: "eid",
            uniqueId: "eid",
            url: prefix + "/list",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            escape: true,
            showPageGo: true,
            rememberSelected: true,
            modalName: "基本信息",
            columns: [{
                checkbox: true
            }, {
                field: 'badge',
                title: '员工编号',
            },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'age',
                    title: '年龄'
                },
                {
                    field: 'compname',
                    title: '公司名称'
                },
                {
                    field: 'departname',
                    title: '部门名称'
                },
                {
                    field: 'compDepJobName',
                    title: '全称'
                },
                {
                    field: 'hxgg',
                    title: '核心高管'
                },
                {
                    field: 'jobGradename',
                    title: '岗位级别'
                }]
        };
        $.table.init(options);
    }

    function queryDeptTree() {
        var url = ctx + "jinpeng/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#compID").val('');
            $("#depID").val('');
            var id = treeNode.id;
            if(id > 10000 && id <= 30000){
                $("#compID").val(id - 10000);
            }else if(id > 30000){
                $("#depID").val(id - 30000);
            }
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryDeptTree();
    });

    function exchange() {
        var row = $("#emp-table").bootstrapTable('getSelections');
        var num = 0;
        var allEid = "";
        if (row.length == 0) {
            $.modal.alertWarning("请选择需要调岗的人员");
            return;
        }
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allEid += row[i].eid
            } else {
                allEid += row[i].eid + ","
            }
        }
        //调岗先判断是否有人已经有离岗申请
        $.ajax({
            async: false,
            url: "/jinpeng/exchangeVer",
            data: {
                "allEid": allEid
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data > 0) {
                    $.modal.alertWarning("选中人员中已有申请过离职的人员，请重试!");
                    return;
                } else {
                    $.operate.exchange(allEid);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });

    }

    function chekDate() {
        var row = $("#emp-table").bootstrapTable('getSelections');
        var allEid = "";
        if (row.length == 0) {
            $.modal.alertWarning("请选择需要离职的人员");
            return;
        }

        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allEid += row[i].eid
            } else {
                allEid += row[i].eid + ","
            }
        }
        /*
        //离职先判断是否有人已经申请了调岗
        $.ajax({
            async: false,
            url: "/jinpeng/exQuitVer",
            data: {
                "allEid": allEid
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data > 0) {
                    $.modal.alertWarning("选中人员中已有申请过调岗的人员，请重试!");
                    return;
                } else {
                    $("#eid").val(allEid);
                    $("#modal").click();
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
*/
        $("#eid").val(allEid);
        $("#modal").click();
    }

    function exQuit() {
        var alleid = $("#eid").val();
        var effectdate = $("#effectdate").val();
        alert(alleid);
        $.ajax({
            async: false,
            url: "/jinpeng/exQuit",
            data: {
                "alleid": alleid,
                "effectdate": effectdate
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data == -1) {
                    $.modal.alertWarning("已有已经设置过离职的人员，生效日期当天状态自动为离职!");
                    $("#missmodal").click();
                    return;
                }
                $.modal.alertSuccess('成功设置' + data + "人离职,系统会根据生效时间自动将人员设置为离职状态。")
                $("#missmodal").click();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }


</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>